<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<ul id="events"></ul>

<script type="application/javascript">
    function add(message) {
        const el = document.createElement("li");
        el.innerHTML = message;
        document.getElementById("events").appendChild(el);
    }

    var eventSource = new EventSource("/temperature-stream");
    eventSource.onmessage = ev => {
        const t = JSON.parse(ev.data);
        const fixed = Number(t.value).toFixed(2);
        add('Temperature:' + fixed + ' C');
    };
    eventSource.onopen = ev => add('Connection opened');
    eventSource.onerror = ev => add('Connection closed');
</script>

</body>
</html>